/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.jx.web;

//import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.alibaba.fastjson.JSON;
//import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.utils.excel.ExportExcel;
import com.thinkgem.jeesite.modules.food.entity.FoodExpenditureRecords;
import com.thinkgem.jeesite.modules.food.entity.FoodInfo;
import com.thinkgem.jeesite.modules.food.entity.FoodSupplier;
import com.thinkgem.jeesite.modules.qc.entity.Assets;
import com.thinkgem.jeesite.modules.qc.entity.Financial;
import com.thinkgem.jeesite.modules.qc.entity.SeniorAssets;
import com.thinkgem.jeesite.modules.jx.entity.FinancingBankInformation;
import com.thinkgem.jeesite.modules.jx.entity.PersonnelManagement;
import com.thinkgem.jeesite.modules.jx.entity.ProjectAimTarget;
import com.thinkgem.jeesite.modules.jx.entity.ProjectPerformanceReport;
import com.thinkgem.jeesite.modules.jx.entity.SecurityDriver;
import com.thinkgem.jeesite.modules.jx.entity.TanantInformation;
import com.thinkgem.jeesite.modules.jx.service.FinancingBankInformationService;
import com.thinkgem.jeesite.modules.jx.service.PersonnelManagementService;
import com.thinkgem.jeesite.modules.sys.entity.Office;
import com.thinkgem.jeesite.modules.sys.service.OfficeService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
//import com.thinkgem.jeesite.modules.sys.entity.Office;
import com.thinkgem.jeesite.modules.test.entity.ReturnData;

/**
 * 融资主体Controller
 * @author 
 * @version  
 */
@Controller
@RequestMapping(value = "${adminPath}/jx/financingBankInformation")
public class FinancingBankInformationController extends BaseController {

	@Autowired
	private FinancingBankInformationService financingBankInformationService;
//	private FinancingBankInformationService FinancingBankInformation;
	private DateFormat sdf;
	@ModelAttribute
	public FinancingBankInformation get(@RequestParam(required=false) String id) {
		FinancingBankInformation entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = financingBankInformationService.get(id);
		}
		if (entity == null){
			entity = new FinancingBankInformation();
		}
		return entity;
	}
	 @RequestMapping(value = {"list", ""})
	public String list(FinancingBankInformation financingBankInformation, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<FinancingBankInformation> page = financingBankInformationService.findPage(new Page<FinancingBankInformation>(request, response),financingBankInformation); 
		model.addAttribute("page", page);	
		return "modules/jx/financingBankInformationList";
	} 
	
	 @ResponseBody
		@RequestMapping(value = {"listByAjax"})
		public String listByAjax(HttpServletRequest request, HttpServletResponse response, Model model)throws ParseException {
			
			String updateDate = request.getParameter("updateDate");
			String createDate = request.getParameter("createDate");//时间查询
			//String incomeDateStr = request.getParameter("incomeDateStr");
		
			/*KpiProjectPerformanceReportId kpiProjectPerformanceReportId = new KpiProjectPerformanceReportId();
			kpiProjectPerformanceReportId.setId(kpiProjectPerformanceReportIdId);*/
		/*	FoodIncome foodIncome = new FoodIncome();
			foodIncome.setOffice(office);*/
			FinancingBankInformation financingBankInformation = new FinancingBankInformation();
			if(updateDate != null && !updateDate.equals("") && createDate != null && !createDate.equals("")){
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				financingBankInformation.setUpdateDate(sdf.parse(updateDate));
				financingBankInformation.setCreateDate(sdf.parse(createDate));
			} //时间的判断获取
			
			List<FinancingBankInformation> financingBankInformationList = financingBankInformationService.findList(financingBankInformation);//数据库接收的集合
		 
			/*for(int i=0;i<financingBankInformationList.size();i++){
				FinancingBankInformation projectAimTarget2 = financingBankInformationList.get(i);
				projectAimTarget2.setTargetOne(DictUtils.getDictLabel(projectAimTarget2.getTargetOne(), "jx_projectPerformanceReport_targetOne", ""));
				projectAimTarget2.setTargetTow(DictUtils.getDictLabel(projectAimTarget2.getTargetTow(),"jx_projectPerformanceReport_targetTow",""));
				projectAimTarget2.setTargetThree(DictUtils.getDictLabel(projectAimTarget2.getTargetThree(),"jx_projectPerformanceReport_targetThree",""));
				projectAimTarget2.setPerformanceStandards(DictUtils.getDictLabel(projectAimTarget2.getPerformanceStandards(),"jx_projectPerformanceReport_performanceStandards",""));
				projectAimTargetList.set(i, projectAimTarget2);
			}		 */
			ReturnData returnData = new ReturnData();
			returnData.setCode("0");
			returnData.setCount(String.valueOf(financingBankInformationList.size()));
			returnData.setData(financingBankInformationList);
			String jsonData = JSON.toJSONString(returnData);
			System.out.println(jsonData);
			return jsonData;
		}
		
	 
	 
	@RequestMapping(value = "form")
	public String form(FinancingBankInformation financingBankInformation, Model model) {
		model.addAttribute("FinancingBankInformation", financingBankInformation);
		return "modules/jx/financingBankInformationForm";
	}
	/*public String form(FinancingBankInformation financingBankInformation, Model model) {
		if(financingBankInformation != null && financingBankInformation.getId() != null && !financingBankInformation.getId().equals("")){
			financingBankInformation = financingBankInformationService.get(financingBankInformation);
			if(financingBankInformation.getId() != null && !financingBankInformation.getId().equals("")){
				financingBankInformation.setId((sdf.format(financingBankInformation.getId())));
			}
		}
		model.addAttribute("foodInfo", financingBankInformation);
		return "modules/jx/financingBankInformationForm";
	}*/
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(String dataString, Model model, RedirectAttributes redirectAttributes) {
			dataString = StringEscapeUtils.unescapeHtml4(dataString);
			FinancingBankInformation financingBankInformation = JSON.parseObject(dataString,FinancingBankInformation.class);
			financingBankInformationService.save(financingBankInformation);
			String status =  JSON.toJSONString("保存数据成功");
			return status;
		}

	@ResponseBody
	@RequestMapping(value = "deleteById")
	public String delete(String id, RedirectAttributes redirectAttributes) {
		FinancingBankInformation financingBankInformation = new FinancingBankInformation();
		financingBankInformation.setId(id);
		financingBankInformationService.delete(financingBankInformation);
		String status =  JSON.toJSONString("删除数据成功");
		return status;
	}

}